package servlets.tools;

import dao.IdaoLocal;
import entities.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * eCOM - Adopte un Presta - Mars-Avril 2013
 * @author Kheira, Jef, William, Tuan-Long
 */
public class CalcIdMax {

    public CalcIdMax() {
    }
    
    public int getMaxIdCommandes(List<Commande> l1, List<Commande> l2) {
        int result = 1;
        int max_l1 = 1;
        int max_l2 = 1;
        
        if (l1 != null) 
        {
            if (l1.size() == 0) 
            {
                max_l1 = 1; 
            }
            else if (l1.size() == 1) 
            {
                max_l1 = l1.get(l1.size() -1).getIdCommande();  
            }
            else if (l1.size() > 1)   
            {
                max_l1 = l1.get(l1.size() -1).getIdCommande();       
            }
        }

        if (l2 != null) 
        {
            if (l2.size() == 0) 
            {
                max_l2 = 1; 
            }
            else if (l2.size() == 1) 
            {
                max_l2 = l2.get(l2.size() -1).getIdCommande();  
            }
            else if (l2.size() > 1)   
            {
                max_l2 = l2.get(l2.size() -1).getIdCommande();       
            }
        }
        
        if (max_l1 >= max_l2) 
        {
            result = max_l1;
        }
        else 
        {
            result = max_l2;
        }
        
        System.err.println("CalcIdMax -- result ==" + String.valueOf(result));
        return result;
    }
}
